var util = require('../../utils/util.js');
const md = require('../../utils/md5.js');
const app = getApp();
const post = require('../../utils/post.js');
Page({

  data: {
    search:0
  },
  onLoad: function (options) {
    var that = this;
    that.chushi();
  },
  searchbank: function () {
    var that = this;
    // 获取成员信息
    var datas = {};
    if (that.data.key==''){
      that.hot();
      that.setData({
        search:0
      })
      return;
    }
    let len = that.data.key.length;
    let keys = '';
    if(len>1){
      keys = "'"
      for(let i=0;i<len;i++){
        keys+= "%"+that.data.key.charAt(i);
      }
      keys+="%'";
    }else{
      keys = "'%" + that.data.key+"%'";
    }
    datas.where = "BankName like " +keys;
    var datacall = function (res) {
      // console.log(res);
      if (res.data.data.length != 0) {
        that.setData({
          hotinfo: res.data.data,
          search:1
        })
      }else{
        that.setData({
          hotinfo:[],
          search: 1
        })
      }
    }
    var res2 = post.getdata("/BO/BA_Bank/Query", datas, datacall);
  },
  getkey: function (e) {
    this.setData({
      key: e.detail.value
    })
  },
  chushi:function(){
    var that = this;
    var datas = {};
    var datacall = function (res) {
      console.log(res);
      if (res.data.data.length != 0) {
        that.setData({
          allinfo: res.data.data
        })
        that.hot();
      }
    }
    var res2 = post.getdata("/BO/BA_Bank/Query", datas, datacall);
  },
  hot:function(){
    var that = this;
    var datas = {};
    datas.where = "IsMain = 1";
    var datacall = function (res) {
      console.log(res);
      if (res.data.data.length != 0) {
        that.setData({
          hotinfo: res.data.data
        })
      }
    }
    var res2 = post.getdata("/BO/BA_Bank/Query", datas, datacall);
  },
  pinyinpaixu:function(arr){
    if (!String.prototype.localeCompare)
      return null;

    var letters = "*abcdefghjklmnopqrstwxyz".split('');
    var zh = "阿八嚓哒妸发旮哈讥咔垃痳拏噢妑七呥扨它穵夕丫帀".split('');

    var segs = [];
    var curr;
    letters.forEach(function (item, i) {
      curr = { letter: item, data: [] };
      arr.forEach(function (item2) {
        if ((!zh[i - 1] || zh[i - 1].localeCompare(item2) <= 0) && item2.localeCompare(zh[i]) == -1) {
          curr.data.push(item2);
        }
      });
      if (curr.data.length) {
        segs.push(curr);
        curr.data.sort(function (a, b) {
          return a.localeCompare(b);
        });
      }
    });
    return segs;
  },
  choosebank:function(e){
    var that =this;
    var bankname = e.currentTarget.dataset.bank;
    console.log(bankname)
    wx.setStorageSync('bankname', bankname);
    wx.navigateBack({
      delta:1
    })
  }
})